package com.ruoyi.web.controller.community.owner;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.community.domain.OwnerVote;
import com.ruoyi.community.service.IOwnerVoteService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 业委会投票Controller
 * 
 * @author ruoyi
 * @date 2021-08-08
 */
@RestController
@RequestMapping("/community/owner/vote")
public class OwnerVoteController extends BaseController
{
    @Autowired
    private IOwnerVoteService ownerVoteService;

    /**
     * 查询业委会投票列表
     */
    @PreAuthorize("@ss.hasPermi('community:vote:list')")
    @GetMapping("/list")
    public TableDataInfo list(OwnerVote ownerVote)
    {
        startPage();
        List<OwnerVote> list = ownerVoteService.selectOwnerVoteList(ownerVote);
        return getDataTable(list);
    }

    /**
     * 导出业委会投票列表
     */
    @PreAuthorize("@ss.hasPermi('community:vote:export')")
    @Log(title = "业委会投票", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OwnerVote ownerVote)
    {
        List<OwnerVote> list = ownerVoteService.selectOwnerVoteList(ownerVote);
        ExcelUtil<OwnerVote> util = new ExcelUtil<OwnerVote>(OwnerVote.class);
        return util.exportExcel(list, "业委会投票数据");
    }

    /**
     * 获取业委会投票详细信息
     */
    @PreAuthorize("@ss.hasPermi('community:vote:query')")
    @GetMapping(value = "/{voteId}")
    public AjaxResult getInfo(@PathVariable("voteId") String voteId)
    {
        return AjaxResult.success(ownerVoteService.selectOwnerVoteById(voteId));
    }

    /**
     * 新增业委会投票
     */
    @PreAuthorize("@ss.hasPermi('community:vote:add')")
    @Log(title = "业委会投票", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OwnerVote ownerVote)
    {
        return toAjax(ownerVoteService.insertOwnerVote(ownerVote));
    }

    /**
     * 修改业委会投票
     */
    @PreAuthorize("@ss.hasPermi('community:vote:edit')")
    @Log(title = "业委会投票", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OwnerVote ownerVote)
    {
        return toAjax(ownerVoteService.updateOwnerVote(ownerVote));
    }

    /**
     * 删除业委会投票
     */
    @PreAuthorize("@ss.hasPermi('community:vote:remove')")
    @Log(title = "业委会投票", businessType = BusinessType.DELETE)
	@DeleteMapping("/{voteIds}")
    public AjaxResult remove(@PathVariable String[] voteIds)
    {
        return toAjax(ownerVoteService.deleteOwnerVoteByIds(voteIds));
    }
}
